import { app, BrowserWindow } from "electron";
import { CustomScheme } from './customScheme'
import { CommonWindowEvent } from "./commonWindowEvent";

process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = "true";
app.on("browser-window-created", (e, win) => {
  CommonWindowEvent.regWinEvent(win);
});
let mainWindow: BrowserWindow;

app.whenReady().then(() => {
  const config = {
    show: false, // 窗口取消立即显示
    frame: false, // 无边框窗口
    webPreferences: {
      nodeIntegration: true, // node环境集成到渲染进程
      webSecurity: false,
      allowRunningInsecureContent: true,
      contextIsolation: false, // 同一个JavaScript上下文中使用Electron API
      webviewTag: true,
      spellcheck: false,
      disableHtmlFullscreenWindowResize: true,
    },
  };
  mainWindow = new BrowserWindow(config);
  if (process.argv[2]) {
    // 打开开发者调试工具
    mainWindow.webContents.openDevTools({ mode: "bottom" })
    // 加载命令行的第三个参数
    mainWindow.loadURL(process.argv[2]);
  } else {
    CustomScheme.registerScheme()
    mainWindow.loadURL('app://index.html')
  }
  CommonWindowEvent.listen();
});
